package com.glodon.paas.activity.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.glodon.paas.activity.api.bean.Activity;
import com.glodon.paas.activity.dao.domain.ActivityEntity;
import com.glodon.paas.exception.PaasServerExceptionFactory;

public class ActivityEntityHelp {

    // public static ActivityEntity mokeActivityEntity(){
    // long time = System.currentTimeMillis();
    // ActivityEntity en = new ActivityEntity();
    // en.setActorId("uid");
    // en.setActorName("hch");
    // en.setId(UUIDUtil.getUUIDStr());
    // en.setActivityType(ActivityConstant.activityType_upload);
    // en.setAppId(102);
    // en.setItemId("testSourceItemId");
    // en.setItemType("102001");
    // en.setItemName("aaa.jpg");
    // en.setActivityTime(new Date(time - 3000));
    // en.setCreateTime(new Date(time - 2000));
    // en.setAppId(ActivityConstant.app_paas_docunemt);
    // return en;
    // }
    
    public static ActivityEntity toActivityEntity(Activity activity) {
        if (activity == null) {
            return null;
        }
        ActivityEntity entity = new ActivityEntity();
        try {
            BeanUtils.copyProperties(entity, activity);
        } catch (Exception e) {
            throw PaasServerExceptionFactory.systemException(e.getMessage(), null);
        }

        return entity;
    }
    
    /**
     * 
     * @param activity
     * @return
     */
    public static ActivityEntity clone(ActivityEntity activity) {
        if (activity == null) {
            return null;
        } 
        try {
             Object entity = BeanUtils.cloneBean(activity);
            return (ActivityEntity)entity;
        } catch (Exception e) {
            throw PaasServerExceptionFactory.systemException(e.getMessage(), null);
        }
    }

    public static Activity toActivity(ActivityEntity entity) {
        if (entity == null) {
            return null;
        }
        Activity activity = new Activity();
        try {
            BeanUtils.copyProperties(activity, entity);
        } catch (Exception e) {
            throw PaasServerExceptionFactory.systemException(e.getMessage(), null);
        }

        return activity;
    }

    public static List<Activity> toActivity(List<ActivityEntity> entityList) {
        if (entityList == null) {
            return null;
        }
        List<Activity> list = new ArrayList<Activity>();
        for (ActivityEntity en : entityList) {
            list.add(toActivity(en));
        }
        return list;
    }
}
